#!/bin/sh
#
# Run a simple backup, then create some
#   new files, do an Incremental onto a different medium
#   and then restore everything.
#
# This script uses the virtual disk autochanger
#
TestName="incremental-2media"
JobName=Inc2media
. scripts/functions


scripts/cleanup
scripts/copy-2disk-confs
scripts/prepare-disk-changer
change_jobname $JobName

# Directory to backup.
# This directory will be created by setup_data().
BackupDirectory="${tmp}/data"

# Use a tgz to setup data to be backed up.
# Data will be placed at "${tmp}/data/".
setup_data data/small.tgz

# the default fileset FS_TESTJOB backups all file and directories defined in "${tmp}/file-list".
echo "${BackupDirectory}" >${tmp}/file-list


start_test

# Write out bconsole commands
cat <<END_OF_DATA >${cwd}/tmp/bconcmds
@$out /dev/null
messages
@$out ${cwd}/tmp/log1.out
label storage=tape volume=TestVolume001 slot=1 Pool=Default drive=0
label storage=File volume=TestVolume002 Pool=Default
run job=$JobName yes
wait
messages
quit
END_OF_DATA

run_susan

print_debug "Backup 1 done"
# make some files for the incremental to pick up
echo "test" > ${BackupDirectory}/test1.txt
echo "test" > ${BackupDirectory}/test2.txt

cat <<END_OF_DATA >${cwd}/tmp/bconcmds
@$out /dev/null
messages
@$out ${cwd}/tmp/log1.out
@# Force Incremental on the second Volume
update volume=TestVolume001 VolStatus=Used
setdebug level=51 storage=File
run level=Incremental job=$JobName storage=File yes
wait
messages
@#
@# now do a restore
@#
@$out ${cwd}/tmp/log2.out
setdebug level=151 storage=tape
restore where=${cwd}/tmp/susan-restores select all done
yes
wait
restore where=${cwd}/tmp/susan-restores select all done
yes
wait
status storage=tape
messages
quit
END_OF_DATA

run_bconsole

check_for_zombie_jobs storage=File
stop_susan

check_two_logs
check_restore_diff

end_test
